﻿//
$.fn.infiniteCarousel = function() {
    function repeat(str, num) {
        return new Array(num + 1).join(str);
    }
    return this.each(function() {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),

            singleWidth = $single.outerWidth(),
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);
        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }
        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft: '+=' + left
            }, 500, function() {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                }
                currentPage = page;
            });
            return false;
        }
        $wrapper.after('<a class="arrow back"></a><a class="arrow forward"></a>');
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function() {
            return gotoPage(currentPage - 1);
        });

        $('a.forward', this).click(function() {
            return gotoPage(currentPage + 1);
        });
        // create a public interface to move to a specific page
        $(this).bind('goto', function(event, page) {
            gotoPage(page);
        });
    });
};

$(function() { $('#centercont').equalHeights(); });

function showQuestion() {

    //            var p = $("#BtnAsk");
    //            var offset = p.offset();


    document.getElementById('divQuestion').style.display = '';

    var sWidth = document.documentElement.offsetWidth > document.body.scrollWidth ? document.documentElement.offsetWidth : document.body.scrollWidth;
    var sHeight = document.documentElement.offsetHeight > document.body.scrollHeight ? document.documentElement.offsetHeight : document.body.scrollHeight;

    document.getElementById('divBackground').style.width = sWidth + "px";
    document.getElementById('divBackground').style.height = sHeight + "px";

    document.getElementById('divAskQuestion').style.left = document.documentElement.scrollLeft + screen.availWidth / 2 - 200 + "px";
    document.getElementById('divAskQuestion').style.top = document.documentElement.scrollTop + screen.availHeight / 2 - 300 + "px";


    //document.getElementById('divAskQuestion').style.left = offset.left -220+ "px";
    //document.getElementById('divAskQuestion').style.top = offset.top - 330 + "px";
    // $("body").scrollTop(offset.top); 
}

function showComment() {


    //            var p = $("#comment_m");
    //            var offset = p.offset();


    document.getElementById('divComment').style.display = '';

    var sWidth = document.documentElement.offsetWidth > document.body.scrollWidth ? document.documentElement.offsetWidth : document.body.scrollWidth;
    var sHeight = document.documentElement.offsetHeight > document.body.scrollHeight ? document.documentElement.offsetHeight : document.body.scrollHeight;

    document.getElementById('divCommentBack').style.width = sWidth + "px";
    document.getElementById('divCommentBack').style.height = sHeight + "px";

    document.getElementById('divCommentcontent').style.left = document.documentElement.scrollLeft + screen.availWidth / 2 - 200 + "px";
    document.getElementById('divCommentcontent').style.top = document.documentElement.scrollTop + screen.availHeight / 2 - 300 + "px";


    //document.getElementById('divCommentcontent').style.left = offset.left-220 + "px";
    //document.getElementById('divCommentcontent').style.top = offset.top - 330 + "px";
    //$("body").scrollTop(offset.top);
}
function closeDiv(ole) {
    document.getElementById(ole).style.display = 'none';
}
function displayDiv(ole) {
    document.getElementById(ole).style.display = '';
    if (document.getElementById("txtTel").style.display != '') {
        document.getElementById("txtTel").focus();
    }
}
function closeComment() {
    document.getElementById('divComment').style.display = 'none';
}
function closeQuestion() {
    document.getElementById('divQuestion').style.display = 'none';
}
function sub_verify(fname) {
    if (document.forms[fname].asktext.value.length <= 0) {
        alert("请输入您提问的内容！");
        document.forms[fname].asktext.select();

        return false;
    }

    else {
        closeQuestion();
        return true;
    }
}
function sub_verifycomment(fname) {

    if (document.forms[fname].text.value.length <= 0) {
        alert("请输入您提问的内容！");
        document.forms[fname].text.select();
        return false;
    } else if (document.forms[fname].text.value == "在此输入评论内容...")
    {
        alert("请输入您提问的内容！");
        document.forms[fname].text.select();
        return false;
    }
    else if (document.getElementById("hidStarPoint").value == "0") {
        alert("您还没有为该商品评级！");
        return false;
    }
    else {
        closeComment();
        return true;
    }
}



function picture() {
    document.getElementById("picture").className = "picicon current";
    document.getElementById("video").className = "vodicon";
    document.getElementById("showpicture").style.display = "block";
    document.getElementById("showvideo").style.display = "none";
    document.getElementById("hidvideostate").value = '1';

}
function video() {
    document.getElementById("picture").className = "picicon";
    document.getElementById("video").className = "vodicon current";
    document.getElementById("showpicture").style.display = "none";
    document.getElementById("showvideo").style.display = "block";
    document.getElementById("hidvideostate").value = '2';

}


function regoldpushhid() {
    document.getElementById("regoldpush").style.display = "none";
}

function regoldpushhidele(ele) {
    document.getElementById(ele).style.display = "none";
}

function CheckMobilePhone() {
    if (!isMobilephone(document.getElementById('txtTel').value)) {
        alert("手机格式错！");
        return false;
    }
    else {
        return true;
    }
}

function isMobilephone(str) {
    var result = str.match(/^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|154|155|156|157|158|159|180|181|182|183|184|185|186|187|188|189|177)\d{8}$/);
    if (result == null) return false;
    return true;
}

function Buying() {
    var strSrc = $("#addtocartbutton").attr("src");
    $("#hd_addtocartbut_src").val(strSrc); //保存购买图片地址 用于恢复购买按钮状态
    //$("#addtocartbutton").attr("src", "../images/adding2bag.gif");
    $("#addtocartbutton").attr({ src: "../images/adding2bag.gif", disabled: "disabled" }); //将购买按钮图片修改成购买中并禁用
    $("#addtocartbt_copy").click();
    return false;
    //if ($("#addtocartbutton").is(":enabled")) { }
}
//选中当前商品
function ChoosesProduct(chooProduct, skn) {
    var totalMoney = 0;
    var originalTotalMoney = 0;
    $(chooProduct).toggleClass("xz");
    $(".GroupSeller_cont ol li[id^=skn_]").each(function () {
        var skn = $(this).attr("id").replace("skn_", "");
        var classxz = $(this).find("a[id$='linkHrefProduct']").attr("class")
        if (classxz) {
            //$(".GroupSeller_cont ol li[id^=skn_] a[id$='linkHrefProduct'][class='xz']")
            var price = $(this).find("#price" + skn).html().replace("¥", "");
            totalMoney += parseInt(price);
            var originalMoney = $(this).find("input[id$='hidwebPrice']").val();
            originalTotalMoney += parseInt(originalMoney);
            $("#originalPrice").html(originalTotalMoney + "元");
            $("#groupPrice").html("<em>组合价：</em>¥" + totalMoney);
            $("#spanEconomizePrice").html("<em>节省了：</em>" + (parseInt(originalTotalMoney) - parseInt(totalMoney)) + "元");
        }

    });

}


